//获取该用户的岗位联动初始化数据
function getData()
{
	var token=localStorage.getItem("token");
	var id = tl_config.his_url;
	var str = id.substring(id.indexOf("id=")+3, id.length);
	str = str.substring(0, str.indexOf("&"));

	$.ajax({   
		url : server_url + 'rest/postEdit.do?ran='+Math.random(),
		type : 'get',
		dataType : 'json',
		async : false,
		data : {
			id : str,
			token: token
		},
		success : function(data) {
			if (data.retCode = "0000") {
				console.log(data.data[0]);
				$("#id").val(eval(data.data)[0].id);
				$("#postName").val(eval(data.data)[0].postName);
				$("#postDesc").text(eval(data.data)[0].postDesc);

				var maxLen=data.data[0].orgId5?5:data.data[0].orgId4?4:data.data[0].orgId3?3:data.data[0].orgId2?2:data.data[0].orgId1?1:0;
				for (var i=1;i<=maxLen;i++){
					$("body").data("orgId" + i,eval(data.data)[0]['orgId' + i]);
				}
				$("body").data("id", eval(data.data)[0].id);
				$("body").data("postName",eval(data.data)[0].postName);
				$("body").data("postDesc",eval(data.data)[0].postDesc);
				$("body").data("maxLen",maxLen);


			} else
				easyDialog.open({
					container:{
						header:'温馨提示',
						content:data.retMsg
					},
					autoClose : 2000
				});
		}
	});
	$("body").data("id",str);
	queryOrg($("body").data("orgId" + $("body").data("maxLen")));
}

//查询的联动
//二级组织
function queryOrg_2() {
	var token=localStorage.getItem("token");
	var obj = document.getElementById("orgId1"); // 定位id
	var index = obj.selectedIndex; // 选中索引
	var select = document.getElementsByTagName("select");
	var len = select.length;
	for (var i = 2; i <= len; i++) {
		var mySelect = document.getElementById("orgId" + i);
		mySelect.remove();
	}
	if (index != 0) {
	$.ajax({
		type : 'get',
		contentType : 'application/json',
		data : {
			orgId : $("#orgId1").val(),
			token:token
		},
		url : server_url + 'rest/getPostOrgNext.do?ran='+Math.random(),
		dataType : 'json',
		success : function(data) {
			if(0!=eval(data.data).length){
				var mySelect = document.createElement("select");
	            mySelect.id = "orgId2"; 
	            document.body.appendChild(mySelect);
			    $("#orgId1").after(mySelect);
			    document.getElementById("orgId2").setAttribute("onclick", "javascript:checkOrgName();");
			    
				$("#orgId2 option").remove();
				$("#orgId2").append(
						
						"<option value='' selected='selected'>---全部---</option>");

				for ( var i = 0; i < eval(data.data).length; i++) {
					$("<option value='" + eval(data.data)[i].id + "'>"+ eval(data.data)[i].orgName + "</option>").appendTo("#orgId2");
				}
				$("#orgId2 option[value='"+$("#orgId2").val()+"']").attr("selected","true");
			}
				$("#orgId2").change(queryOrg3);
		}
	});
	}
}
	
//查询的联动
//三级组织
function queryOrg_3() {
	var token=localStorage.getItem("token");
	var obj = document.getElementById("orgId2"); // 定位id
	var index = obj.selectedIndex; // 选中索引
	var select = document.getElementsByTagName("select");
	var len = select.length;
	for (var i = 3; i <= len; i++) {
		var mySelect = document.getElementById("orgId" + i);
		mySelect.remove();
	}
	if (index != 0) {
	$.ajax({
		type : 'get',
		contentType : 'application/json',
		data : {
			orgId : $("#orgId2").val(),
			token:token
		},
		url : server_url+'rest/getPostOrgNext.do?ran=' + Math.random(),
		dataType : 'json',
		success : function(data) {

			if(0!=eval(data.data).length){
					var mySelect = document.createElement("select");
			          mySelect.id = "orgId3"; 
			          document.body.appendChild(mySelect);
			          $("#orgId2").after(mySelect);
					  document.getElementById("orgId3").setAttribute("onclick", "javascript:checkOrgName();");
					
					$("#orgId3 option").remove();
					$("#orgId3").append(
							
							"<option value='' selected='selected'>---全部---</option>");
					
					for ( var i = 0; i < eval(data.data).length; i++) {
						$("<option value='" + eval(data.data)[i].id + "'>"+ eval(data.data)[i].orgName + "</option>").appendTo("#orgId3");
					}
					$("#orgId3 option[value='"+$("#orgId3").val()+"']").attr("selected","true");
			}
			$("#orgId3").change(queryOrg4);
		}
	});
	}
}

//查询的联动
//四级组织
function queryOrg_4() {

	var token=localStorage.getItem("token");	
	var obj = document.getElementById("orgId3"); // 定位id
	var index = obj.selectedIndex; // 选中索引
	var select = document.getElementsByTagName("select");
	var len = select.length;
	for (var i = 4; i <= len; i++) {
		var mySelect = document.getElementById("orgId" + i);
		mySelect.remove();
	}
	if (index != 0) {
	$.ajax({
		type : 'get',
		contentType : 'application/json',
		data : {
			orgId : $("#orgId3").val(),
			token:token
		},
		url : server_url+'rest/getPostOrgNext.do?ran=' + Math.random(),
		dataType : 'json',
		success : function(data) {

			if(0!=eval(data.data).length){
					var mySelect = document.createElement("select");
			          mySelect.id = "orgId4"; 
			          document.body.appendChild(mySelect);
			          $("#orgId3").after(mySelect);
					  document.getElementById("orgId4").setAttribute("onclick", "javascript:checkOrgName();");
					
					$("#orgId4 option").remove();
					$("#orgId4").append(
							
							"<option value='' selected='selected'>---全部---</option>");
					
					for ( var i = 0; i < eval(data.data).length; i++) {
						$("<option value='" + eval(data.data)[i].id + "'>"+ eval(data.data)[i].orgName + "</option>").appendTo("#orgId4");
					}
					$("#orgId4 option[value='"+$("#orgId4").val()+"']").attr("selected","true");
					
			}
			$("#orgId4").change(queryOrg5);
		}
	});
	}
}

//查询的联动
//五级组织
function queryOrg_5() {

	var token=localStorage.getItem("token");
	var obj = document.getElementById("orgId4"); // 定位id
	var index = obj.selectedIndex; // 选中索引
	var select = document.getElementsByTagName("select");
	var len = select.length;
	for (var i = 5; i <= len; i++) {
		var mySelect = document.getElementById("orgId" + i);
		mySelect.remove();
	}
	if (index != 0) {
	$.ajax({
		type : 'get',
		contentType : 'application/json',
		data : {
			orgId : $("#orgId4").val(),
			token:token
		},
		url : server_url+'rest/getPostOrgNext.do?ran=' + Math.random(),
		dataType : 'json',
		success : function(data) {

			if(0!=eval(data.data).length){
					var mySelect = document.createElement("select");
			          mySelect.id = "orgId5"; 
			          document.body.appendChild(mySelect);
			          $("#orgId4").after(mySelect);
					  document.getElementById("orgId5").setAttribute("onclick", "javascript:checkOrgName();");
					
					$("#orgId5 option").remove();
					$("#orgId5").append(
							
							"<option value='' selected='selected'>---全部---</option>");
					
					for ( var i = 0; i < eval(data.data).length; i++) {
						$("<option value='" + eval(data.data)[i].id + "'>"+ eval(data.data)[i].orgName + "</option>").appendTo("#orgId5");
					}
				$("#orgId5 option[value='"+$("#orgId5").val()+"']").attr("selected","true");
			}
		}
	});
	}
}


//初始化数据的联动
//一级组织
function queryOrg(orgId1){
	var token=localStorage.getItem("token");
	$("#orgId1 option").remove();
	$.ajax({
		type : 'get',
		dataType : 'json',
		url : server_url + 'rest/getPostOrg.do?ran=' + Math.random()+ '&token=' + token,
		success : function(data) {
			if(data.retCode=="0000"){
				$("<option value=''>"+"--全部--"+"</option>").appendTo("#orgId1");
				for ( var i = 0; i < eval(data.data).length; i++) {
					
					$("<option value='" + eval(data.data)[i].id + "'>"+ eval(data.data)[i].orgName + "</option>").appendTo("#orgId1");
				}
				$("#orgId1 option[value='"+orgId1+"']").attr("selected","true");
				if ($("body").data("maxLen")-1>0){
					$("#orgId1").change(queryOrg2($("body").data("orgId" + [$("body").data("maxLen")-1])));
				}
				document.getElementById("orgId1").setAttribute("onchange", "javascript:queryOrg_2();");
			}else{
			}
		}
	});
}

//初始化数据的联动
//二级组织
function queryOrg2(orgId2) {
	var token=localStorage.getItem("token");
	var obj = document.getElementById("orgId1"); // 定位id
	var index = obj.selectedIndex; // 选中索引
	var select = document.getElementsByTagName("select");
	var len = select.length;
	for (var i = 2; i <= len; i++) {
		var mySelect = document.getElementById("orgId" + i);
		mySelect.remove();
	}
	if (index != 0) {
	$.ajax({
		type : 'get',
		contentType : 'application/json',
		data : {
			orgId : $("#orgId1").val(),
			token:token
		},
		url : server_url + 'rest/getPostOrgNext.do?ran=' + Math.random(),
		dataType : 'json',
		success : function(data) {
			if(0!=eval(data.data).length){
				var mySelect = document.createElement("select");
	            mySelect.id = "orgId2"; 
	            document.body.appendChild(mySelect);
			    $("#orgId1").after(mySelect);
			    document.getElementById("orgId2").setAttribute("onclick", "javascript:checkOrgName();");
			    
				$("#orgId2 option").remove();
				$("#orgId2").append(
						
						"<option value='' selected='selected'>---全部---</option>");

				for ( var i = 0; i < eval(data.data).length; i++) {
					$("<option value='" + eval(data.data)[i].id + "'>"+ eval(data.data)[i].orgName + "</option>").appendTo("#orgId2");
				}
				$("#orgId2 option[value='"+orgId2+"']").attr("selected","true");
				
			}
			if ($("body").data("maxLen")-2>=1){
				$("#orgId2").change(queryOrg3($("body").data("orgId" + [$("body").data("maxLen")-2])));
			}
			document.getElementById("orgId2").setAttribute("onchange", "javascript:queryOrg_3();");
		}
	});
	}
}
	
//初始化数据的联动
//三级组织
function queryOrg3(orgId3) {
	var token=localStorage.getItem("token");
	var obj = document.getElementById("orgId2"); // 定位id
	var index = obj.selectedIndex; // 选中索引
	var select = document.getElementsByTagName("select");
	var len = select.length;
	for (var i = 3; i <= len; i++) {
		var mySelect = document.getElementById("orgId" + i);
		mySelect.remove();
	}
	if (index != 0) {
	$.ajax({
		type : 'get',
		contentType : 'application/json',
		data : {
			orgId : $("#orgId2").val(),
			token:token
		},
		url : server_url + 'rest/getPostOrgNext.do?ran=' + Math.random(),
		dataType : 'json',
		success : function(data) {

			if(0!=eval(data.data).length){
					var mySelect = document.createElement("select");
			          mySelect.id = "orgId3"; 
			          document.body.appendChild(mySelect);
			          $("#orgId2").after(mySelect);
					  document.getElementById("orgId3").setAttribute("onclick", "javascript:checkOrgName();");
					
					$("#orgId3 option").remove();
					$("#orgId3").append(
							
							"<option value='' selected='selected'>---全部---</option>");
					
					for ( var i = 0; i < eval(data.data).length; i++) {
						$("<option value='" + eval(data.data)[i].id + "'>"+ eval(data.data)[i].orgName + "</option>").appendTo("#orgId3");
					}
					$("#orgId3 option[value='"+orgId3+"']").attr("selected","true");
					
			}
			if ($("body").data("maxLen")-3>=1){
				$("#orgId3").change(queryOrg4($("body").data("orgId" + [$("body").data("maxLen")-3])));
			}
			document.getElementById("orgId3").setAttribute("onchange", "javascript:queryOrg_4();");
		}
	});
	}
}

//初始化数据的联动
//四级组织
function queryOrg4(orgId4) {

	var token=localStorage.getItem("token");	
	var obj = document.getElementById("orgId3"); // 定位id
	var index = obj.selectedIndex; // 选中索引
	var select = document.getElementsByTagName("select");
	var len = select.length;
	for (var i = 4; i <= len; i++) {
		var mySelect = document.getElementById("orgId" + i);
		mySelect.remove();
	}
	if (index != 0) {
	$.ajax({
		type : 'get',
		contentType : 'application/json',
		data : {
			orgId : $("#orgId3").val(),
			token:token
		},
		url : server_url + 'rest/getPostOrgNext.do?ran=' + Math.random(),
		dataType : 'json',
		success : function(data) {

			if(0!=eval(data.data).length){
					var mySelect = document.createElement("select");
			          mySelect.id = "orgId4"; 
			          document.body.appendChild(mySelect);
			          $("#orgId3").after(mySelect);
					  document.getElementById("orgId4").setAttribute("onclick", "javascript:checkOrgName();");
					
					$("#orgId4 option").remove();
					$("#orgId4").append(
							
							"<option value='' selected='selected'>---全部---</option>");
					
					for ( var i = 0; i < eval(data.data).length; i++) {
						$("<option value='" + eval(data.data)[i].id + "'>"+ eval(data.data)[i].orgName + "</option>").appendTo("#orgId4");
					}
					$("#orgId4 option[value='"+orgId4+"']").attr("selected","true");
					
			}
			if ($("body").data("maxLen")-4>=1){
				$("#orgId4").change(queryOrg5($("body").data("orgId" + [$("body").data("maxLen")-4])));
			}
			document.getElementById("orgId4").setAttribute("onchange", "javascript:queryOrg_5();");
		}
	});
	}
}

//初始化数据的联动
//五级组织
function queryOrg5(orgId5) {

	var token=localStorage.getItem("token");
	var obj = document.getElementById("orgId4"); // 定位id
	var index = obj.selectedIndex; // 选中索引
	var select = document.getElementsByTagName("select");
	var len = select.length;
	for (var i = 5; i <= len; i++) {
		var mySelect = document.getElementById("orgId" + i);
		mySelect.remove();
	}
	if (index != 0) {
	$.ajax({
		type : 'get',
		contentType : 'application/json',
		data : {
			orgId : $("#orgId4").val(),
			token:token
		},
		url : server_url + 'rest/getPostOrgNext.do?ran=' + Math.random(),
		dataType : 'json',
		success : function(data) {

			if(0!=eval(data.data).length){
					var mySelect = document.createElement("select");
			          mySelect.id = "orgId5"; 
			          document.body.appendChild(mySelect);
			          $("#orgId4").after(mySelect);
					  document.getElementById("orgId5").setAttribute("onclick", "javascript:checkOrgName();");
					
					$("#orgId5 option").remove();
					$("#orgId5").append(
							
							"<option value='' selected='selected'>---全部---</option>");
					
					for ( var i = 0; i < eval(data.data).length; i++) {
						$("<option value='" + eval(data.data)[i].id + "'>"+ eval(data.data)[i].orgName + "</option>").appendTo("#orgId5");
					}
						$("#orgId5 option[value='"+orgId5+"']").attr("selected","true");
			}
		}
	});
	}
}